<?php
  /**
   * @author EVANDRO DE OLIVEIRA.
   * @category APPLICATION
   * @package APPLICATION
   * @since 17/03/2012.
   * @last_update 17/03/2012.
   * @copyright 2012.
   * @version 1.0.
   *
   * Uma solução para Zend_Controlller_Action_Helper_FlashMessenger
   */
  class Bootstrap extends Zend_Application_Bootstrap_Bootstrap{
    protected function _initDoctype(){
      $this->bootstrap('view');
      
      $view = $this->getResource('view');
      
      $view->doctype('XHTML1_TRANSITIONAL');
    }
    
    protected function _initSystem(){
      $frontController = Zend_Controller_Front::getInstance();
      
      require_once(APPLICATION_PATH . '/plugins/View.php');
      $frontController->registerPlugin(new Core_View_Plugin());
      
      // Register segurança plugin
      require_once(APPLICATION_PATH . '/plugins/Seguranca.php');
      $frontController->registerPlugin(new Core_Seguranca_Plugin());
      
      $autoloader = Zend_Loader_Autoloader::getInstance();
      $autoloader->setFallbackAutoloader(true);
      
      /*require_once APPLICATION_PATH . '/library/Core/Commons.php';
      
      require_once APPLICATION_PATH . '/library/Core/ValidaFormulario.php';
      
      require_once APPLICATION_PATH . '/library/Core/FormException.php';
      
      require_once APPLICATION_PATH . '/library/Core/SpreadsheetExcelReader.php';
      
      //require_once APPLICATION_PATH . '/library/Core/AtComp.php';*/
      
      require_once APPLICATION_PATH . '/views/helpers/DbComboBox.php';
      require_once APPLICATION_PATH . '/views/helpers/ComboBox.php';
      require_once APPLICATION_PATH . '/views/helpers/Tag.php';
      
    }
    
    protected function _initDatabase(){
      $config = new Zend_Config_Ini(APPLICATION_PATH . APPLICATION_INI,  APPLICATION_ENV);
      
      $dbadapter = Zend_Db::factory($config->resources->db);
      $dbadapter->getConnection()->query('SET NAMES utf8');
      $dbadapter->getConnection()->query('SET CHARACTER SET utf8');
      
      Zend_Db_Table_Abstract::setDefaultAdapter($dbadapter);
      
      $register = Zend_Registry::getInstance();
      $register->config = $config;
      $register->adapter = $dbadapter;
      
      unset($config, $dbadapter, $register);
    }
    
    protected function _initSendMail(){
      $config = Zend_Registry::getInstance()->config;
      
      if($config->smtp->enable == 1){
        Zend_Mail::setDefaultTransport(
          new Zend_Mail_Transport_Smtp(
            $config->smtp->server, array(
              'auth'      => 'login',
              'username'  => $config->smtp->login,
              'password'  => $config->smtp->password
            )
          )
        );
      }
    }
  }

